﻿Imports System.Windows.Forms

Public Class dlgNewCategory

#Region "Property"

    ''' <summary>
    ''' Thuộc tính lưu đối tượng xử lý các thao tác nghiệp vụ
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 24/10/2010</remarks>
    Public Property BusinessObject() As BL.clsBLBase

    ''' <summary>
    ''' Thuộc tính lưu tên chủng loại
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 15/11/2010</remarks>
    Public Property CategoryName() As String
#End Region

#Region "Event"

    ''' <summary>
    ''' Bấm thêm thì thực hiện việc thêm chủng loại
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>Nguyễn Huy Thường added on 14/08/2011</remarks>
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Try
            If vldCheckInput.Validate.IsValid Then
                CategoryName = txtCategoryName.Text
                Dim categoryID As Guid = Guid.NewGuid
                Dim drNewRow As BL.FMSDataSet.CategoryRow = BusinessObject.dsFMS.Category.NewCategoryRow
                With drNewRow
                    .CategoryID = categoryID
                    .CategoryAlias = txtCategoryAlias.Text
                    .CategoryName = CategoryName
                    .CategoryAddedDate = Today
                    .CategoryStatus = True
                    .CategoryDescription = txtDescription.Text
                End With
                BusinessObject.dsFMS.Category.Rows.Add(drNewRow)
                If BusinessObject.EditRecord(BusinessObject.dsFMS.Category.Rows.Find(categoryID)) Then
                    BusinessObject.dsFMS.Category.AcceptChanges()
                    Me.DialogResult = System.Windows.Forms.DialogResult.OK
                    Me.Close()
                Else
                    CategoryName = String.Empty
                End If
            End If
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Bấm cancel thì hủy việc thay đổi dữ liệu
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>Nguyễn Huy Thường added on 14/08/2011</remarks>
    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Try
            BusinessObject.dsFMS.Category.RejectChanges()
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Close()
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub
#End Region

End Class
